<?php


namespace App\Http\Traits;


use Illuminate\Support\Arr;

class GlobalConstant
{

    //统一数组分隔符
    const DELIMITER_CHARACTER = ",";

    const KIND_LIST = [
        1 => '蔬果类',
        2 => '畜牧类',
//        3 => '种植类'
    ];

    const ROLE_LIST = [
        ['value' => 1, 'text' => '教师'],
        ['value' => 2, 'text' => '学生']
    ];

    const SEARCH_CATEGORY = [
        ['value' => 1, 'text' => '校区热度'],
        ['value' => 2, 'text' => '课程热度'],
        ['value' => 3, 'text' => '讨论热度'],
    ];

    const PAY_TYPE_LIST = [
        'wx'     => '微信支付',
        'alipay' => '支付宝支付'
    ];

    public static function setMarkerLabel($content)
    {
        $label              = new \stdClass();
        $label->content     = $content;
        $label->color       = '#319eec';
        $label->fontSize    = 13;
        $label->borderColor = '#000';
        $label->anchorX     = -60;
        $label->anchorY     = -84;
        return $label;
    }

    public static function setMarkerLabel2($content)
    {
        $label              = new \stdClass();
        $label->content     = $content;
        $label->color       = '#319eec';
        $label->fontSize    = 10;
        $label->borderColor = '#000';
        $label->anchorX     = -60;
        $label->anchorY     = -68;
        return $label;
    }

    public static function getRoleMap($key = "ALL")
    {
        $ret = self::ROLE_LIST;
        if ($key === "ALL") {
            return $ret;
        }
        return Arr::get($ret, $key, false);
    }

    public static function getSearchCategoryMap($key = "ALL")
    {
        $ret = self::SEARCH_CATEGORY;
        if ($key === "ALL") {
            return $ret;
        }
        return Arr::get($ret, $key, false);
    }


    public static function getKindMap($key = "ALL")
    {
        $ret = self::KIND_LIST;
        if ($key === "ALL") {
            return $ret;
        }
        return Arr::get($ret, $key, false);
    }

    public static function getPayTypeMap($key = "ALL")
    {
        $ret = self::PAY_TYPE_LIST;
        if ($key === "ALL") {
            return $ret;
        }
        return Arr::get($ret, $key, false);
    }

    public static function changeOrderBy($value = 1)
    {
        if ($value == 1) {
            return 'desc';
        }
        return 'asc';
    }

    public static function delimiterPrice($price)
    {
        return explode('.', $price);
    }


    public static function showOrderRefundBtn($order)
    {
        //已付款并且未提交过退款申请
        if ($order->status == 1 && $order->refund_status == 0) {
            return true;
        }
        return false;
    }

}
